package com.atguigu.common.exception;

import com.atguigu.common.results.ResultCodeEnum;

import java.math.BigDecimal;

public abstract class Assert {
    //4、判断数字等于0  否则抛出异常
    public static void assertCountEq0(int count){
        if(count!=0){
            throw new BusinessException(ResultCodeEnum.MOBILE_EXIST_ERROR);
        }
    }
    //3、判断字符串是否为空  如果为空抛出异常
    public static void assertStrNotNull(String str){
        if(str==null || "".equals(str.trim())){
            throw new BusinessException(ResultCodeEnum.OBJECT_IS_NULL);
        }
    }
    //1、判断对象是否为空，如果为空抛出自定义异常
    public static void assertObjNotNull(Object obj){
        if(obj==null){
            throw new BusinessException(ResultCodeEnum.OBJECT_IS_NULL);
        }
    }
    //2、判断BigDecimal不能为空也不能为0  否则抛出异常
    public static void assertBigDecimalNotNull(BigDecimal bigDecimal){
        if(bigDecimal==null ||
                bigDecimal.intValue()==0 ){
            //借款额度不能为0
            throw new BusinessException(ResultCodeEnum.BORROW_AMOUNT_NULL_ERROR);
        }
    }

    public static void assertCodeNotEq(String redisCode, String code) {
        if( redisCode==null || "".equals(redisCode.trim()) || !redisCode.equals(code)){
            throw new BusinessException(ResultCodeEnum.CODE_ERROR);
        }
    }
}
